package com.qutan.app.core.domain;

import com.i7time.entity.User;
import com.qutan.app.core.domain.enumclass.*;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;

/**
 *Created by pwy on 16/5/15
 *
 * 用户
 *
 */
@Entity
@Table(name = "user")
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
public class UserInfo extends IDEntity {

    @Column(columnDefinition = "varchar (40) comment '用户名' ", unique = true)
    private String username;

    @Column(columnDefinition = "varchar (100) default ''  comment '密码' ")
    private String password;

    @Column(columnDefinition = "bigint comment '用于跟密码加密的一个动态字符串(时间戳)'")
    private Long passwordTimestamp;

    @Column(columnDefinition = "varchar (40) comment '昵称' ")
    private String nick_name;

    @Column(columnDefinition = "varchar (11) comment '手机号码' ",unique = true)
    private String tel;

    @Column(columnDefinition = "int comment '性别0.女,1.男,2.其他' ")
    @Enumerated(EnumType.ORDINAL)
    private SexType sex;

    @Column(columnDefinition = "varchar (40) comment '生日'   default ''")
    private String birthday="";

    @Column(columnDefinition = "varchar (80) comment '照片' ")
    private String pictures="";

    @Column(columnDefinition = "varchar (80) comment '头像' ")
    private String avatar="";

    @Column(columnDefinition = "varchar (40) comment '邮箱' ")
    private String mail;

    @Column(columnDefinition = "varchar (80) comment '地址' ")
    private String address;

    @Column(columnDefinition = "varchar (50) comment '用户状态(启用:ENABLE,禁用:DISABLE)' ")
    @Enumerated(EnumType.STRING)
    private UserStatus userStatus;

    @Column(columnDefinition = "int(11) comment '是否第三方登录，0非第三方，1微信，2QQ,3微博 '")
    @Enumerated(EnumType.ORDINAL)
    private ThreeLogin isThirdLogin;


    @Column(columnDefinition = "varchar (40) comment '第三方登录的id'")
    private String thirdLoginId="";

    @Column(columnDefinition = "varchar (40) comment '直播频道号'")
    private String live_channel;

    @Column(columnDefinition = "varchar (40) comment '直播的上传url'")
    private String up_url;

    @Column(columnDefinition = "varchar (40) comment '直播的下载url'")
    private String down_url;

    @Enumerated(EnumType.ORDINAL)
    @Column(columnDefinition = "int comment '对应的角色ID'")
    private RoleType role;

    @Column(columnDefinition = "varchar (40) comment '第三方登陆ID'",unique = true)
    private String openId;

    @Column(columnDefinition = "bigint comment '所在的场景ID'")
    private Long sceneId;

    //错误提示
    public static final String password_error = "密码错误";
    public static final String username_is_not_null = "用户名不能为空";
    public static final String username_is_exist = "用户名已存在";
    public static final String username_is_not_exist = "用户名不存在";
    public static final String password_is_not_null = "密码不能为空";

    // 密码 md5 加密的key
    public static final String ssoPasswordEncodeKey = "xc??vn()&^i@!#Y*!&@Tkl~~deh#*!ut@#!$ks√fhs213@1234vx>>>..';[]5938˜∫√ƒ45$@#&$T@&#$^!@#!*#$^*!^#*&^<>M";

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getPasswordTimestamp() {
        return passwordTimestamp;
    }

    public void setPasswordTimestamp(Long passwordTimestamp) {
        this.passwordTimestamp = passwordTimestamp;
    }

    public String getNick_name() {
        return nick_name;
    }

    public void setNick_name(String nick_name) {
        this.nick_name = nick_name;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public SexType getSex() {
        return sex;
    }

    public void setSex(SexType sex) {
        this.sex = sex;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public UserStatus getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(UserStatus userStatus) {
        this.userStatus = userStatus;
    }

    public ThreeLogin getIsThirdLogin() {
        return isThirdLogin;
    }

    public void setIsThirdLogin(ThreeLogin isThirdLogin) {
        this.isThirdLogin = isThirdLogin;
    }

    public String getThirdLoginId() {
        return thirdLoginId;
    }

    public void setThirdLoginId(String thirdLoginId) {
        this.thirdLoginId = thirdLoginId;
    }

    public String getLive_channel() {
        return live_channel;
    }

    public void setLive_channel(String live_channel) {
        this.live_channel = live_channel;
    }

    public String getUp_url() {
        return up_url;
    }

    public void setUp_url(String up_url) {
        this.up_url = up_url;
    }

    public String getDown_url() {
        return down_url;
    }

    public void setDown_url(String down_url) {
        this.down_url = down_url;
    }

    public RoleType getRole() {
        return role;
    }

    public void setRole(RoleType role) {
        this.role = role;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getPictures() {
        return pictures;
    }

    public void setPictures(String pictures) {
        this.pictures = pictures;
    }

    public User converInfo2User(){
        String avatar= StringUtils.isBlank(this.avatar)?"":this.avatar;
        String birthday=StringUtils.isBlank(this.thirdLoginId)?"":this.thirdLoginId;
        String userName=StringUtils.isBlank(this.username)?"":this.username;
        String nickName=StringUtils.isBlank(this.nick_name)?"":this.nick_name;
        String thirdLoginId=StringUtils.isBlank(this.thirdLoginId)?"":this.thirdLoginId;
        int sex=this.sex==null?SexType.FEMALE.getSort():this.sex.getSort();
        int isThirdLogin=this.isThirdLogin==null?ThreeLogin.NORMAL.getSort():this.isThirdLogin.getSort();
        String pictures=StringUtils.isBlank(this.pictures)?"":this.pictures;
        int role=this.role==null?RoleType.NORMAL.getSort():this.role.getSort();
        String tel=StringUtils.isBlank(this.tel)?"":this.tel;
        User user =new User(this.id,userName,this.password,nickName,
                String.valueOf(sex),avatar,birthday,String.valueOf(isThirdLogin),String.valueOf(thirdLoginId),
                pictures,String.valueOf(role),tel);
        return  user;
    }


}
